//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Dialogue node
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to.
//   Cell 4 - This group a or b?

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_walk;
short sent_alert = 0;

body;

beginstate INIT_STATE;
	set_level(ME,26);
	
	if (gf(68,11) > 0)
		set_attitude(ME,10);
		

	if (gf(68,12) > 0)
		erase_char(ME);
	if (gf(68,2) > 0)
		erase_char(ME);
		
	last_walk = get_current_tick();
	break;

beginstate DEAD_STATE;
	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		set_attitude(1002,10);
		alert_char(1002);
		set_act_at_dist(1002,1);
		set_attitude(1003,10);
		alert_char(1003);
		set_act_at_dist(1003,1);
		set_attitude(1004,10);
		set_act_at_dist(1004,1);
		set_attitude(1005,10);
		set_act_at_dist(1005,1);
		}
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if ((gf(68,7) == 0) && (get_attitude(ME) < 10) && (get_nearest_party_char(5) >= 0)) {
		sf(68,7,1);
		talk_no_exit(10);
		}
		
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	if (gf(68,2) > 0) {
		if (dist_to_nav_point(ME,1) <= 2)
			erase_char(ME);
		approach_nav_point(ME,1,1);
		}
		else if ((get_attitude(ME) >= 10) || (gf(68,8 + get_memory_cell(4)) > 0)) {
			if (dist_to_nav_point(ME,2 + get_memory_cell(4)) <= 3)
				fidget(ME,10);
				else approach_nav_point(ME,2 + get_memory_cell(4),1);
			}
			



	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);


	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		set_attitude(1002,10);
		alert_char(1002);
		set_act_at_dist(1002,1);
		set_attitude(1003,10);
		alert_char(1003);
		set_act_at_dist(1003,1);
		set_attitude(1004,10);
		set_act_at_dist(1004,1);
		set_attitude(1005,10);
		set_act_at_dist(1005,1);
		sent_alert = 1;
		}

	do_attack();
break;

beginstate TALKING_STATE;
	if (gf(68,2) > 0) {
		print_str("Talking: Now that there is a break in the Shaper line, this");
		print_str("  creation is currently fleeing the camp.");
		}
	else if ((gf(68,6) > 0) || (gf(68,8 + get_memory_cell(4)) > 0)) {
		print_str("Talking: This creation is too distracted to pay attention right now.");
		}
		else begin_talk_mode(get_memory_cell(0));
	break;